<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>添加巡查</title>
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/globle.css" />
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <style>
        /* body {
      padding-top: 25px;
    } */

        span {
            margin: 10px;
        }

        .Tabl {
            height: 50px;
            width: 88%;
            font-size: 14px;
            font-weight: bold;
            text-align: left;
            margin-left: 6%;
        }

        .Td1 {
            color: #b8b8b8;
            width: 110px;
        }

        .Td2 {
            color: #000000;
            text-align: left;

        }

        .Hr {
            height: 1px;
            width: 96%;
            background-color: #faf7f7;
            margin-left: 2%;
        }

        .Butt {
            border: 1px solid #b8b8b8;
            border-radius: 20px;
            color: #ffffff;
            height: 17px;
            width: 17px;
            outline: none;
        }

        .TabImg {
            height: 150px;
            width: 96%;
            margin-left: 2%;
            border: 10px solid #d8d8d8;
        }

        .TdImg1 {
            height: 110px;
            width: 90px;
        }

        .TdImg2 {
            height: 110px;
            width: 90px;
        }

        .ButAdd {
            height: 110px;
            width: 100px;
            font-size: 100px;
            color: #ffffff;
            background-color: #b8b8b8;
        }

        .TabL {
            height: 75px;
            width: 88%;
            font-size: 16px;
            font-weight: bold;
            text-align: left;
            margin-left: 6%;
        }

        .ButL {
            height: 40px;
            width: 100%;
            background-color: #d0d0d0;
            /* position: fixed; */
            bottom: 0;
        }

        .Td3 {
            background-color: #1abc9c;
            text-align: center;
            width: 50%;
        }

        select {
            appearance: none;
            -moz-appearance: none;
            -webkit-appearance: none;
            border: none;
            background: none;
        }
    </style>
</head>

<body>
    <form action="" id="myForm">
        <button style="background-color: #F2F2F2;height: 40px;width: 100%;font-size: 18px;">发布清单区域</button>
        <input type="hidden" id="id" name="id" />
        <input type="hidden" id="proId" name="proId" />
        <input type="hidden" id="enterpriseId" name="enterpriseId" />
        <input type="hidden" id="enterpriseProjectsId" name="areaId" />
        <input type="hidden" name="userId" id="userId">
        <table class="Tabl">
            <tr>
                <td class="Td1">发布人：</td>
                <td class="Td2">
                    <input name="publishUser" id="publishUser" readonly placeholder="" />
                </td>
            </tr>
        </table>
        <hr class="Hr" />
        <table class="Tabl">
            <tr>
                <td class="Td1">预期时间：</td>
                <td class="Td2">
                    <input type="date" id="completeTime" name="repairTime" />
                </td>
            </tr>
        </table>
        <hr class="Hr" />
        <table class="Tabl">
            <tr>
                <td class="Td1">维修内容：</td>
            </tr>
        </table>
        <table class="TabL">
            <tr>
                <td>
                    <textarea rows="3" cols="35" id="repairContext" name="repairContext" placeholder=""></textarea>
                </td>
            </tr>
        </table>
        <hr class="Hr" />
        <table class="Tabl">
            <tr>
                <td class="Td1">标段名称：</td>
                <td class="Td2">
                    <input id="departProjectId" type="text" name="areaName" readonly />
                </td>
            </tr>
        </table>
        <hr class="Hr" />
        <table class="Tabl">
            <tr>
                <td class="Td1">绿地名称：</td>
                <td class="Td2">
                    <select id="urisId" name="urisId">
                        <option value="">请选择</option>
                    </select>
                </td>
            </tr>
        </table>
        <hr class="Hr" />
        <table class="Tabl">
            <tr>
                <td class="Td1">维修人员：</td>
                <td class="Td2">
                    <select id="receiver" name="receiver">
                        <option value="">请选择</option>
                    </select>
                </td>
            </tr>
        </table>

        <img id="bbs">
        <hr class="Hr" />
        <div style="padding: 10px;">
            <ul class="upload-ul clearfix">
                <li class="upload-pick">
                    <div class="webuploader-container clearfix" id="goodsUpload"></div>
                </li>
            </ul>
        </div>

        <button style="background-color: #F2F2F2;height: 40px;width: 100%;font-size: 18px;">执行任务区域</button>
        <table class="ButL">
            <tr>
                <td class="Td3">
                    <div style="color: #ffffff;" onclick="submitList()">
                        发布
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>
<script src="../../script/webuploader.js"></script>
<script src="../../script/jquery.js"></script>
<script src="../../script/diyUpload.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>

<script type="text/javascript">
    var $tgaUpload = $("#goodsUpload").diyUpload({
        url: BaseServiceUrl + "mobile/repairManage/uploadRepairImage.json",
        success: function (data) {
            console.log(data);
        },
        error: function (err) { },
        buttonText: "",
        accept: {
            title: "Images",
            extensions: "gif,jpg,jpeg,bmp,png",
            mimeTypes: 'image/*'
        },
        thumb: {
            width: 600,
            height: 600,
            quality: 100,
            allowMagnify: false,
            crop: false,
            type: "image/jpeg",
        },
    });
    $tgaUpload.options.formData.dids = null;
    $tgaUpload.options.formData.did1 = null;

    // 当有文件被添加进队列的时候

    apiready = function () {
        var ret = $api.getStorage("selectpor");
        $("#enterpriseProjectsId").val(ret.id);
        if (ret != undefined) {
            var proId = $api.getStorage("userSession").data.proId;
            $("#proId").val(proId); //項目id
            $("#userId").val($api.getStorage("userSession").data.id)
            $("#departProjectId").val(ret.projectName);
            var sids = ret.id;
            $.ajax({
                type: "post",
                async: true, //同步执行
                url: BaseServiceUrl + "mobile/admin/list.json",
                data: {
                    proId: proId.toString(),
                    areaid: sids.toString(),
                },
                dataType: "json", //返回数据形式为json
                success: function (result) {
                    // alert(JSON.stringify(result));
                    var v = result.obj;
                    var select = document.getElementById("urisId");
                    for (var i = 0; i < v.length; i++) {
                        var opt = document.createElement("option");
                        // 设置option元素的内容，内容为传入的数组内容
                        opt.innerText = v[i].greedLandAdministrator.name;
                        opt.value = v[i].id;
                        // 把option添加到select中
                        select.appendChild(opt);
                    }
                    $("#urisId").val(v.id);
                },
            });
            var reg = $api.getStorage("userSession");
            $("#urisId").change(() => {
                //alert(typeof $("#urisId").val());
                var greenId = parseInt($("#urisId").val());
                if (reg != undefined) {
                    $("#typeId").val(reg.data.id); //admin id
                    var sids = reg.data.enterprise.id;
                    var enterProject = ret.id;
                    $.ajax({
                        type: "post",
                        async: false, //同步执行
                        url: BaseServiceUrl + "mobile/admin/select.json",
                        data: {
                            greenId: greenId,
                            enterprise: sids,
                            enterpriseProjects: enterProject,
                        },
                        dataType: "json", //返回数据形式为json
                        success: function (result) {
                            var v = result.obj;
                            var select = document.getElementById("receiver");
                            $("#receiver").empty()
                            for (var i = 0; i < v.length; i++) {
                                var opt = document.createElement("option");
                                // 设置option元素的内容，内容为传入的数组内容
                                opt.innerText = v[i].name;
                                opt.value = v[i].id;
                                // 把option添加到select中
                                select.appendChild(opt);
                            }
                            $("#receiver").val(v.id);
                        },
                    });
                }
            });
        }
        $("#enterpriseId").val(reg.data.enterprise.id);
        $("#publishUser").val(reg.data.name);

    };

    $.fn.ghostsf_serialize = function () {
        var a = this.serializeArray();
        var $radio = $("input[type=radio],input[type=checkbox]", this);
        var temp = {};
        $.each($radio, function () {
            if (!temp.hasOwnProperty(this.name)) {
                if ($("input[name='" + this.name + "']:checked").length == 0) {
                    temp[this.name] = "";
                    a.push({
                        name: this.name,
                        value: "",
                    });
                }
            }
        });
        return a;
    };

    function submitList() {
        var source = $("#repairContext").val();
        if (source == null || source == "") {
            alert("请输入维修内容");
            return false;
        }

        var urisId = $("#urisId").val();

        if (urisId == null || urisId == "") {
            alert("请选择绿地名称");
            return false;
        }
        var receiver = $("#receiver").val();
        if (receiver == null || receiver == "") {
            alert("请输选择问题接收方");
            return false;
        }
        var completeTime = $("#completeTime").val();

        if (completeTime == null || completeTime == "") {
            alert("请输入要求完成时间");
            return false;
        }
        var proId = $("#proId").val();
        var typeId = $("#typeId").val();
        var departProjectId = $("#departProjectId").val();

        var formObject = {};
        var formArray = $("#myForm").ghostsf_serialize();
        $.each(formArray, function (i, item) {
            formObject[item.name] = item.value;
        });
        console.log(JSON.stringify(formObject))

        $.ajax({
            url: BaseServiceUrl + "mobile/repairManage/saveRepair.json",
            type: "POST",
            data: {
                data: JSON.stringify(formObject),
            },
            dataType: "json",
            success: function (req) {
                // console.log(JSON.stringify(req))
                $tgaUpload.options.formData.dids = req.obj.id;
                $tgaUpload.upload();
                if (req.code == 0) {
                    api.showProgress({
                        //打开开关
                        title: "提交中...",
                        text: "",
                    });
                    setTimeout(function () {
                        api.closeWin();
                    }, 5000);
                }
            },
        });
    }
</script>

</html>